#include "oal_hash.h"
#include "abts.h"
#include <oal.h>





static int freecnt = 0;
static void test_free(void *arg){
	freecnt ++;
}
static void test_hash_fun(abts_case *tc, void *data){
	const char *key1 = "123456";
	const char *key2 = "abcdef";
	void *value1 = (void *)1;
	void *value2 = (void *)2;

	oal_hash_t *ht;
	int i;
	void *v;

	//创建
	ht = oal_hash_create(128);
	ABTS_PTR_NOTNULL(tc,ht);
	oal_hash_set_free(ht,test_free);

	oal_hash_put(ht,key1,value1);
	oal_hash_put(ht,key2,value2);
	v = oal_hash_get(ht,key1);
	ABTS_PTR_EQUAL(tc,value1,v);
	v = oal_hash_get(ht,key2);
	ABTS_PTR_EQUAL(tc,value2,v);
	i = oal_hash_count(ht);
	ABTS_INT_EQUAL(tc,2,i);

	v = oal_hash_remove(ht,key1);
	ABTS_PTR_EQUAL(tc,value1,v);
	i = oal_hash_count(ht);
	ABTS_INT_EQUAL(tc,1,i);

	freecnt = 0;
	oal_hash_delete(ht,key2);
	ABTS_INT_EQUAL(tc,1,freecnt);
	i = oal_hash_count(ht);
	ABTS_INT_EQUAL(tc,0,i);

	oal_hash_put(ht,key1,value1);
	oal_hash_put(ht,key2,value2);

	freecnt = 0;
	oal_hash_clear(ht);
	ABTS_INT_EQUAL(tc,2,freecnt);
	i = oal_hash_count(ht);
	ABTS_INT_EQUAL(tc,0,i);


	oal_hash_put(ht,key1,value1);
	oal_hash_put(ht,key2,value2);
	freecnt = 0;

	oal_hash_destory(ht);
	ABTS_INT_EQUAL(tc,2,freecnt);
}


abts_suite *test_hash(abts_suite *suite)
{
	suite = ADD_SUITE(suite);
	abts_run_test(suite,test_hash_fun,NULL);
	return suite;
}